package com.polaris.live.popup

import android.content.Context
import android.view.View
import android.view.ViewGroup
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.common.cacha.UserManager
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.constant.LiveConst
import com.polaris.live.databinding.PopupMyBeansStartPlayBinding
import com.polaris.live.resp.back_resp.LiveShowMessageResp
import com.polaris.live.utils.CommonUtils

/**
 * MyBeansStartPlayPopup
 *
 * @author Created by 半仙 on 2024/4/12/012 14:31
 */
class MyBeansStartPlayPopup(
    context: Context,
    private val mLiveShowMessageResp: LiveShowMessageResp,
    private val mOnSelectListener: ((type: Int) -> Unit),
) : BottomPopupView(context) {

    private lateinit var mBinding: PopupMyBeansStartPlayBinding
    override fun getImplLayoutId(): Int {
        return R.layout.popup_my_beans_start_play
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupMyBeansStartPlayBinding.bind(popupImplView)

        mBinding.apply {

            if (!CommonUtils.isMan(UserManager.getUser().sex) && !mLiveShowMessageResp.onlyWait) {
                startMatch.visibility = View.GONE
            }
            startMatch.setOnSingleClickListener {
                mOnSelectListener.invoke(LiveConst.Type.ONLY_MATCH)
                dismiss()
            }
            matchAndLive.setOnSingleClickListener {
                mOnSelectListener.invoke(LiveConst.Type.LIVE_AND_MATCH)
                dismiss()
            }
            startLive.setOnSingleClickListener {
                mOnSelectListener.invoke(LiveConst.Type.ONLY_LIVE)
                dismiss()
            }
            startParty.setOnSingleClickListener {
                mOnSelectListener.invoke(LiveConst.Type.PARTY_LIVE)
                dismiss()
            }
        }

        NavigationBarUtils.setNavigationHeightIfTransparent(mBinding.vLine) { view, height ->
            val layoutParams = view.layoutParams as ViewGroup.LayoutParams
            layoutParams.height = height
            mBinding.vLine.layoutParams = layoutParams
        }
    }
}